// packageA/appraiseSuccess/index.js
import Toast from '@vant/weapp/toast/toast';
import moment from 'moment'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        resourceURL: `${wx.api.host}/`,
        uinfo: wx.getStorageSync("uinfo"),
        accumulation: '',
        nick_name: "",
        avatar: "",
        page: 1,
        limit: 10,
        UserGrowthLog: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let {
            accumulation,
            nick_name,
            avatar
        } = this.data.uinfo
        this.setData({
            accumulation,
            nick_name,
            avatar,
        })
        this.getUserGrowthLog()
    },
    getUserGrowthLog() {
        Toast.loading({
            message: '加载中...',
            duration: 0,
            forbidClick: true
        })
        wx.http.get(wx.api.GetUserGrowthLog, {
            page: this.data.page, //页码
            limit: this.data.limit, //每页条数
        }).then((res) => {
            // console.log(res.data.data);
            if (res.code == 1) {
                if (res.data.data.length > 0) {
                    var newarr = res.data.data.map(v => {
                        return {
                            ...v,
                            add_time: moment(Number(v.add_time) * 1000).format('YYYY/MM/DD HH:mm:ss'),
                        }
                    })
                    var arr = [...this.data.UserGrowthLog, ...newarr]
                    this.setData({
                        UserGrowthLog: arr,
                        page: this.data.page + 1
                    })
                    // console.log(this.data.UserGrowthLog);
                }
                if (res.data.data.length <= 0) {
                    Toast('没有更多了')
                    // console.log(res.data.data);
                }
                setTimeout(() => {
                    Toast.clear()
                }, 500);
            }
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        this.getUserGrowthLog()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})